package com.open4cn.simulator.core.ext;

import java.io.Serializable;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-05-13 00:39
 */
public class XriteStatus implements Serializable {

    // 校准阶段
    private CorrectionStageEnum currentCorrectionStage;


    // 当前孔径
    private ApertureEnum currentAperture;

    // 当前镜头距离
    private LensDistanceEnum currentLensDistance;

    // 当前uv值
    private UVEnum currentUV;

    // 当前包含状态
    private SpecularGlossEnum currentSpecularGloss;


    public XriteStatus() {
        init();
    }

    public XriteStatus(String currentAperture, String currentUV, String currentSpecularGloss) {
        init();
        this.currentAperture = ApertureEnum.valueOf(currentAperture);
        this.currentUV = UVEnum.valueOf(currentUV);
        this.currentSpecularGloss = SpecularGlossEnum.valueOf(currentSpecularGloss);
        this.currentLensDistance = LensDistanceEnum.N;
    }

    public XriteStatus(String currentAperture, String currentUV, String currentSpecularGloss, String currentLensDistance) {
        init();
        this.currentAperture = ApertureEnum.valueOf(currentAperture);
        this.currentUV = UVEnum.valueOf(currentUV);
        this.currentSpecularGloss = SpecularGlossEnum.valueOf(currentSpecularGloss);
        this.currentLensDistance = LensDistanceEnum.valueOf(currentLensDistance);
    }

    /**
     * 重置状态
     */
    public void reset() {
        init();
    }

    public void init() {
        currentCorrectionStage = XriteStatus.CorrectionStageEnum.DONE;
        currentAperture = XriteStatus.ApertureEnum.N;
        currentUV = XriteStatus.UVEnum.UV100;
        currentSpecularGloss = XriteStatus.SpecularGlossEnum.SCI;
        currentLensDistance = XriteStatus.LensDistanceEnum.N;
    }


    /**
     * 开始校准
     */
    public void startCorrection() {
        currentCorrectionStage = XriteStatus.CorrectionStageEnum.PRE;
    }

    /**
     * 校准结束
     */
    public void stopCorrection() {
        currentCorrectionStage = XriteStatus.CorrectionStageEnum.DONE;
    }


    public boolean inCorrecting() {
        return !CorrectionStageEnum.DONE.equals(currentCorrectionStage);
    }

    public XriteStatus.SpecularGlossEnum getCurrentSpecularGloss() {
        return currentSpecularGloss;
    }

    /**
     * 切换镜面光泽包含值
     *
     * @param specularGloss
     */
    public void changeSpecularGloss(XriteStatus.SpecularGlossEnum specularGloss) {
        this.currentSpecularGloss = specularGloss;
    }

    public XriteStatus.ApertureEnum getCurrentAperture() {
        return currentAperture;
    }

    /**
     * 切换孔径
     *
     * @param aperture
     */
    public void changeAperture(XriteStatus.ApertureEnum aperture) {
        this.currentAperture = aperture;
    }

    public XriteStatus.UVEnum getCurrentUV() {
        return currentUV;
    }

    /**
     * 切换uv值
     *
     * @param uv
     */
    public void changeUV(XriteStatus.UVEnum uv) {
        this.currentUV = uv;
    }


    public XriteStatus.CorrectionStageEnum getCurrentCorrectionStage() {
        return currentCorrectionStage;
    }

    public void changeCorrectionStage(XriteStatus.CorrectionStageEnum correctionStage) {
        this.currentCorrectionStage = correctionStage;
    }

    public LensDistanceEnum getCurrentLensDistance() {
        return currentLensDistance;
    }

    public void changeLensDistance(LensDistanceEnum currentLensDistance) {
        this.currentLensDistance = currentLensDistance;
    }

    @Override
    public String toString() {
        return "XriteStatus{" +
                "currentCorrectionStage=" + currentCorrectionStage +
                ", currentAperture=" + currentAperture.name() +
                ", currentLensDistance=" + currentLensDistance.name() +
                ", currentUV=" + currentUV.name() +
                ", currentSpecularGloss=" + currentSpecularGloss.name() +
                '}';
    }

    /**
     * -----------------------------------------------------------------------
     **/

    // 孔径枚举
    public enum ApertureEnum {
        N("00", "25"),
        M("", "17"),
        S("23", "10"),
        U("", "6");
        private String code;
        private String size;

        ApertureEnum(String code, String size) {
            this.code = code;
            this.size = size;
        }

        public String getCode() {
            return code;
        }

        public String getSize() {
            return size;
        }

        public static XriteStatus.ApertureEnum of(String code) {
            for (XriteStatus.ApertureEnum item : XriteStatus.ApertureEnum.values()) {
                if (item.name().equals(code)) {
                    return item;
                }
            }
            return null;
        }
    }


    // 镜头距离枚举
    public enum LensDistanceEnum {
        N("25 "), //不要删除结尾空格
        M("17 "),
        S("10 "),
        U("6 ");
        private String code;

        LensDistanceEnum(String code) {
            this.code = code;
        }

        public String getCode() {
            return code;
        }

        public static XriteStatus.LensDistanceEnum of(String code) {
            for (XriteStatus.LensDistanceEnum item : XriteStatus.LensDistanceEnum.values()) {
                if (item.name().equals(code)) {
                    return item;
                }
            }
            return null;
        }
    }


    // uv枚举
    public enum UVEnum {
        UV100("1", "EXC400"),
        UV45("2", "D65"),
        UV0("", "INCLUDED"),
        ;
        private String code;
        private String tag;

        UVEnum(String code, String tag) {
            this.code = code;
            this.tag = tag;
        }

        public String getCode() {
            return code;
        }

        public String getTag() {
            return tag;
        }

        public static XriteStatus.UVEnum of(String code) {
            for (XriteStatus.UVEnum item : XriteStatus.UVEnum.values()) {
                if (item.code.equals(code)) {
                    return item;
                }
            }
            return null;
        }
    }

    // 包含状态枚举
    public enum SpecularGlossEnum {
        SCI("0", "SPIN"),
        SCE("1", "SPEX");
        private String code;
        private String tag;

        SpecularGlossEnum(String code, String tag) {
            this.code = code;
            this.tag = tag;
        }

        public String getCode() {
            return code;
        }

        public String getTag() {
            return tag;
        }

        public static XriteStatus.SpecularGlossEnum of(String code) {
            for (XriteStatus.SpecularGlossEnum item : XriteStatus.SpecularGlossEnum.values()) {
                if (item.code.equals(code)) {
                    return item;
                }
            }
            return null;
        }
    }

    // 校准阶段
    public enum CorrectionStageEnum {
        PRE,
        BLACK_BOARD,
        WHITE_BOARD,
        DONE,
        ;
    }
}
